package com.server.server;

import java.util.ArrayList;
import java.util.List;

import org.apache.mina.core.session.IoSession;

import com.server.app.PlayerManager;
import com.server.object.Player;
import com.server.protocols.SProtocols;
import com.server.request.LoadedGameReq;
import com.server.response.LoadedGameResp;
import com.server.status.SocketState;
import com.webserver.server.net.BaseMessage;
import com.webserver.server.net.BaseServer;

public class LoadedGameServer implements BaseServer {
	public int GetProtocol() {
		return SProtocols.LOADED_GAME;
	}

	public BaseMessage GetRequest() {
		return new LoadedGameReq();
	}

	public BaseMessage handle(IoSession is,BaseMessage request) {
		Player player = PlayerManager.GetInstance().GetPlayer(request.getUserInfo().uid);
		LoadedGameResp resp;
		if(player != null) {
			List<Long> data = new ArrayList<Long>();
			if(player.room != null) {
				data = player.room.LoadedGame(player.uid);
			}
			resp = new LoadedGameResp(SocketState.SUCCESSED.ordinal(), data);
			
		}else {
			resp = new LoadedGameResp(SocketState.RELOGIN.ordinal(), new ArrayList<Long>());
		}
		return resp;
	}
}
